package com.company.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * Created by ruoan on 2020/9/24 23:21
 */
public class MyPostProcessor implements BeanPostProcessor {

    /**
     * 在bean初始化之前执行
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行了类的后置处理器方法postProcessBeforeInitialization，相关bean的名字为"+beanName);
        return bean;
    }

    /**
     * 在bean初始化之后执行
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行了类的后置处理器方法postProcessAfterInitialization，相关bean的名字为"+beanName);
        return bean;
    }
}
